package org.davidliebman.android.awesomewifi;

import android.net.wifi.ScanResult;
import android.net.wifi.WifiConfiguration;

public class WifiListNode {
	
	private int mContents = 0;
	private int mEncryption = 0;
	private int mListInfo = 0;
	private String mDescription = new String("");
	private WifiConfiguration mConfig = null;
	private ScanResult mScan = null;
	
	public static final int CONTAINS_SCANS = 1;
	public static final int CONTAINS_CONFIG = 2;
	public static final int CONTAINS_BOTH = 3;
	
	// Constants used for different security types
    public static final String SCAN_PSK = "PSK";
    public static final String SCAN_WEP = "WEP";
    public static final String SCAN_EAP = "EAP";
    public static final String SCAN_OPEN = "Open";
    public static final String SCAN_WPA = "WPA";
	
	public WifiListNode(ScanResult m) {
		mContents = CONTAINS_SCANS;
		mScan = m;
		mListInfo = CONTAINS_SCANS;
	}
	
	public WifiListNode(WifiConfiguration m) {
		mContents = CONTAINS_CONFIG;
		mConfig = m;
		mListInfo = CONTAINS_CONFIG;
	}
	
	public WifiListNode() {
		mContents = 0;
	}
	
	public int getContents() {
		return mContents;
	}
	public void setContents(int mContents) {
		this.mContents = mContents;
	}
	public String getDescription() {
		return mDescription;
	}
	public void setDescription(String mDescription) {
		this.mDescription = mDescription;
	}
	public WifiConfiguration getConfig() {
		return mConfig;
	}
	public void setConfig(WifiConfiguration mConfig) {
		this.mConfig = mConfig;
	}
	public ScanResult getScan() {
		return mScan;
	}
	public void setScan(ScanResult mScan) {
		this.mScan = mScan;
	}
	
	public int getEncryption() {
		return mEncryption;
	}

	public void setEncryption(int mEncryption) {
		this.mEncryption = mEncryption;
	}

	public int getListInfo() {
		return mListInfo;
	}

	public void setListInfo(int mListInfo) {
		this.mListInfo = mListInfo;
	}

	public void parseScanDescription () {
		mDescription = "Security: ";
		String mFoundSchemes = new String("");
		mEncryption = Wifi.ENCRYPT_DETECTNONE;
		if (mContents == CONTAINS_SCANS || mContents == CONTAINS_BOTH) {

			if (mScan.capabilities.contains(SCAN_WEP)) {
				mFoundSchemes = mFoundSchemes + "WEP ";
				mEncryption = Wifi.ENCRYPT_WEP;

			}
			if (mScan.capabilities.contains(SCAN_OPEN)) {
				mFoundSchemes = mFoundSchemes+ "OPEN ";
				mEncryption = Wifi.ENCRYPT_NONE;

			}
			if (mScan.capabilities.contains(SCAN_WPA)) {
				mFoundSchemes = mFoundSchemes + "WPA/WPA2 ";
				mEncryption = Wifi.ENCRYPT_WPA_WPA2;
			}
			//assemble message
			if(mFoundSchemes.length() > 0) {
				mDescription = mDescription + mFoundSchemes;
			}
			else {
				mDescription = mDescription + "..." +mScan.capabilities;
			}
		}
	}
}
